package com.github.wings27.interview.Problem;

/**
 * Project Name: common-interview-problems
 * Date Created: 2014/02/15 17:49
 *
 * @author Wings
 */
public class VectorRotation {
    public static void main(String[] args) {
        int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        rotate(array,3);
        printArray(array);
        rotate(array,3);
        printArray(array);
        rotate(array,11);
        printArray(array);
    }

    private static void printArray(int[] array) {
        for (int anArray : array) {
            System.out.print(anArray + ",");
        }
        System.out.println();
    }

    public static void rotate(int[] a, int m) {
        int l = a.length;
        int temp = a[0];
        int i;
        for (i = 0; (i * m + m) % l != 0; i++) {
            a[(i * m) % l] = a[(i * m + m) % l];
        }
        a[(i * m) % l] = temp;
    }
}
